#ifndef __GRID_NODE_H__
#define __GRID_NODE_H__

#include <iostream>
#include <vector>
using namespace std;

// 栅格节点
class GP{
    public:
        GP(){};
        GP(int x, int y, float g, float h, size_t idx, std::shared_ptr<GP> parent):x(x),y(y),g(g),h(h),idx(idx),parent(parent){
            this->f = g + h;
        };

        // // 复制构造
        // GP(const GP& n){
        //     this->x = n.x;
        //     this->y = n.y;
        //     this->g = n.g;
        //     this->h = n.h;
        //     this->f = n.f;
        //     this->idx = n.idx;
        //     this->parent = n.parent;
        // }

        int x= 0, y =0;
        float f = 0.0, g = 0.0, h=0.0;
        long idx = 0;
        std::shared_ptr<GP> parent = nullptr;

        void setX(int x){
            this->x = x;
        }

        void setY(int y){
            this->y = y;
        }

        // 
        void setG(float g){
            this->g = g;
            this->f = g + this->h;
        }

        void setH(float h){
            this->h = h;
            this->f = this->g + h;
        }

        void setIdx(long idx){
            this->idx = idx;
        }

        void setParent(std::shared_ptr<GP> n){
            this->parent = n;
        }

        std::shared_ptr<GP> getParent(){
            return this->parent;
        }

        // 重载运算符 +
        GP operator+(const GP& n){
            GP ret;
            ret.setX(this->x + n.x);
            ret.setY(this->y + n.y);
            ret.setG(this->g + n.g);
            ret.setH(this->h + n.h);
            return ret;
        }  

        // 重载运算符 -
        GP operator-(const GP& n){
            GP ret;
            ret.setX(this->x - n.x);
            ret.setY(this->y - n.y);
            return ret;
        } 

        // 重载运算符 ==
        bool operator==(const GP& n){
            return x == n.x && y == n.y;
        }  

        // 重载运算符 !=
        bool operator!=(const GP& n){
            return !operator==(n);
        } 

        // 比较运算符
        struct compare_cost{
            bool operator()(const std::shared_ptr<GP> n1, const std::shared_ptr<GP> n2){
                // Can modify this to allow tie breaks based on heuristic cost if required
                return (n1->f > n2->f) || ((n1->f == n2->f) && (n1->h > n2->h));
            }
        };

};

#endif